<template>
    <div class="orderDetailCont" :style="'min-height: '+docheight+'px'">
      <div class="haspadding" v-if="!showTimeOut&&showCont">
        <div class="addressCont">
          <div class="addressItem">
            <div class="addressImg">张</div>
            <div class="addressInfo">
              <div class="infoTop">
                <div class="userName">张女士</div>
                <div class="userTel">18483613963</div>
              </div>
              <div class="infoAddress">家和未来城小区</div>
            </div>
          </div>
        </div>
        <div class="userCont" >
          <div class="userImg">
            <img src="static/img/goodsImg.png" />
          </div>
          <div class="userInfo">
            <div class="goodsName">
                <div class="goodsNameLeft">
                    <div class="newTag">高级</div>
                    <div>安安老师</div>
                </div>
                <div class="goodsSex">
                    <span class="iconfont icon-xingbie-nan"></span>
                    <span>27</span>
                </div>
            </div>
            <div class="orderTime">
                <div class="orderIconItem">
                    <div class="iconfont icon-shoucang2"></div>
                    <div>4</div>
                </div>
                <div class="orderNum">授课经验：3年</div>
            </div>
          </div>
        </div>
        <div class="detailInfo">
          <div class="shopTop">
            <div class="shopNameCont">
              <div class="shopName">订单号：1245829378428</div>
            </div>
            <div class="orderStatus">待付款</div>
          </div>
          <div class="goodsList">
            <div class="goodsItem">
              <div class="goodsImg">
                <img :src="'static/img/goodsImg.png'+ossSrc">
              </div>
              <div class="goodsInfo">
                <div class="goodsName">语文课程（小学）</div>
                  <div class="goodsType">
                    <div class="goodsTypeItem">已选：10小时</div>
                  </div>
                  <div class="goodsInfoPrice">
                    <div>单价:¥45元/小时</div>
                  </div>
              </div>
            </div>
          </div>
          <div class="formCont">
            <div class="formItem">
              <div class="formName">实付金额</div>
              <div style="color: #f9406e">￥<span style="font-size: 0.9rem">299</span>.00</div>
            </div>
            <div class="formItem">
              <div class="formName">授课时间</div>
              <div>18:00～21:00</div>
            </div>
            <div class="formItem">
              <div class="formName">下单时间</div>
              <div>{{ orderDetail.create_time }}</div>
            </div>
            <div class="formItem">
              <div class="formName">支付时间</div>
              <div>{{ orderDetail.delivery_time }}</div>
            </div>
            <div class="formItem">
              <div class="formName">接单时间</div>
              <div>{{ orderDetail.take_time }}</div>
            </div>
            <div class="formItem">
              <div class="formName">完成时间</div>
              <div>{{ orderDetail.take_time }}</div>
            </div>
            <div class="formItem">
              <div class="formName">退款时间</div>
              <div>{{ orderDetail.take_time }}</div>
            </div>
            <div class="formItem">
              <div class="formName">退款备注</div>
              <div>{{ orderDetail.take_time }}</div>
            </div>
            <div class="formItem">
              <div class="formName">订单备注</div>
              <div>{{ orderDetail.take_time }}</div>
            </div>
          </div>
        </div>
        <div class="detailInfo">
          <div class="headName">打卡记录</div>
          <div class="formCont">
            <div class="formItem noFlex" v-for="(item,index) in 10">
              <div class="setCarItem">
                <div class="formName">打卡时间：</div>
                <div>2023-01-22 19:31:50</div>
              </div>
              <div class="setCarItem">
                <div class="formName">打卡数量：</div>
                <div>3（小时）</div>
              </div>
            </div>
          </div>
        </div>
        
        <div class="ctrlCont">
          <div class="orderBtn greenBtn">立即支付</div>
          <div class="orderBtn greenBtn">取消订单</div>
          <!-- <div class="orderBtn blackBtn" v-if="orderDetail.order_status==1||orderDetail.order_status==2" @click="ctrlFn(1)">取消订单</div>
          <div class="orderBtn pinkBtn" v-if="orderDetail.order_status==3" @click="ctrlFn(2)">确定收货</div>
          <div class="orderBtn blackBtn" v-if="orderDetail.order_status==4||orderDetail.order_status==5||orderDetail.order_status==6" @click="ctrlFn(3)">删除订单</div>
          <div class="orderBtn pinkBtn" v-if="orderDetail.order_status==4&&orderDetail.is_evaluate==1&&orderDetail.order_type!=2" @click="replayOrderFn">评价订单</div> -->
        </div>
      </div>
      <confirm v-model="showConfirm"
        title="操作提示"
        @on-cancel="onCancel"
        @on-confirm="onConfirm"
        >
          <p style="text-align:center;">{{ confirmTip }}</p>
      </confirm>
      <toast v-model="showToast" position="middle" width="50%" type="text" :time="1000">{{showText}}</toast>
      <getLoad v-if="!showCont"></getLoad>
      <getTimeOut v-if="showTimeOut"></getTimeOut>
      <sub-load v-if="showLoad"></sub-load>
    </div>
  </template>
  
  <script>
//   import { orderDetails } from '@/http/userCenter'
//   import { orderCance,orderDel,remindOrder,orderTake } from '@/http/api'
  import {Toast,Confirm } from 'vux'
  import getLoad from '@/components/public/getLoad'
  import getTimeOut from '@/components/public/getTimeOut'
  import subLoad from '@/components/public/subLoad.vue'
  export default {
    components:{subLoad,getTimeOut,getLoad,Toast,Confirm},
    data(){
      return{
        showLoad:false,
        showTimeOut: false,
        showCont:true,
        showText:'',
        showToast:false,
        orderDetail:{},     
        order_id:this.$route.query.id,
        star_rating:3,
        showConfirm:false,
        ctrlStatus:'',
        confirmTip:'',
      }
    },
    methods:{
      replayOrderFn(){
        this.$router.push({path:'/replayOrder',query:{id:this.order_id}})
      },
      onCancel(){
        this.showConfirm = false
      },
      onConfirm(){
        if(this.ctrlStatus == 1){
          this.canceFn()
        }else if(this.ctrlStatus ==2){
          this.orderSure()
        }else if(this.ctrlStatus ==3){
          this.delFn()
        }
      },
      orderSure(){
        let data = {
          order_id:this.order_id
        }
        if(!this.showLoad){
          this.showLoad = true
          orderTake(data).then((res)=>{
            this.showToast = true
            if(res.data.code==1){
              this.showText = '收货成功'
              this.getData()
            }else{
              this.showText = res.data.msg
            }
            this.showLoad = false
          }).catch(()=>{
            this.showLoad = false
            this.showToast = true
            this.showText = '网络请求超时'
          })
        }
      },
      ctrlFn(index){
        if(index==1){
          this.confirmTip = '确定取消订单?'
        }else if(index==2){
          this.confirmTip = '确认商品无误收货?'
        }else if(index==3){
          this.confirmTip = '确定删除订单?'
        }
        this.ctrlStatus = index
        this.showConfirm = true
      },
      delFn(){
        let data ={
          order_id:this.order_id
        }
        if(!this.showLoad){
          this.showLoad = true
          orderDel(data).then((res)=>{
            this.showToast = true
            if(res.data.code==1){
              this.showText = '删除成功'
              setTimeout(() => {
                this.$router.push({path:'/order'})
              }, 1500);
            }else{
              this.showText = res.data.msg
            }
            this.showLoad = false
          }).catch(()=>{
            this.showLoad = false
            this.showToast = true
            this.showText = '网络请求超时'
          })
        }
      },
      canceFn(){
        let data ={
          order_id:this.order_id
        }
        if(!this.showLoad){
          this.showLoad = true
          orderCance(data).then((res)=>{
            if(res.data.code==1){
              this.getData()
            }else{
              this.showToast = true
              this.showText = '订单取消失败'
            }
            this.showLoad = false
          }).catch(()=>{
            this.showLoad = false
            this.showToast = true
            this.showText = '网络请求超时'
          })
        }
      },
      payOrder(){
        this.$router.push({path:'/orderPay',query:{id:this.order_id}})
      },
      remindFn(){
        let data ={
          order_id: this.order_id,
        }
        if(!this.showLoad){
          this.showLoad = true
          remindOrder(data).then((res)=>{
            this.showToast = true
            if(res.data.code==1){
              this.showText = '提醒成功'
            }else{
              this.showText = res.data.msg
            }
            this.showLoad = false
          }).catch(()=>{
            this.showLoad = false
            this.showToast = true
            this.showText = '网络请求超时'
          })
        }
      },
      orderStepFn(){
        this.$router.push({path:'/orderStep',query:{id:this.order_id}})
      },
      toShop(item) {
        this.$router.push({path:'/shopDetail',query:{id:this.orderDetail.shopping_shop_id}})
      },
      toDetail(){
        this.$router.push({path:'/goodsDetail',query:{id:this.orderDetail.shopping_goods_id}})
      },
      getData(){
        let data = {
          order_id :this.order_id
        }
        orderDetails(data).then((res)=>{
          if(res.data.code==1){
            this.orderDetail = res.data.data
          }else{
            this.showToast = true
            this.showText = res.data.msg
          }
          this.showCont= true
        }).catch(()=>{
          this.showTimeOut = true
          this.showCont= true
        })
      }
    },
    beforeRouteLeave(to,from,next){
      if(to.path == "/order"){
        to.meta.keepAlive = true;
      }else{
        to.meta.keepAlive = false;
      }
      next();
    },
    created() {
    //   this.getData()
    }
  }
  </script>
  
  <style scoped lang="less">
  .orderDetailCont{
    width: 100%;
    padding-bottom: 3.75rem;
    padding-top: 0.75rem;
    box-sizing: border-box;
    background-color: #F2F3F3;
    .addressCont{
      width: 100%;
      padding: 0 4%;
      box-sizing: border-box;
      .addressItem{
        background-color: #fff;
        padding: 0.75rem;
        box-sizing: border-box;
        border-radius: 0.25rem;
        display: flex;
        width: 100%;
        align-items: center;
        margin-bottom: 0.75rem;
        .addressImg{
          width: 2.5rem;
          height: 2.5rem;
          border-radius: 50%;
          text-align: center;
          line-height:2.5rem;
          font-size: 0.9rem;
          background-color: #61CCD3;
          color: white;
          margin-right: 0.75rem;
        }
        .addressInfo{
          width: 0.5rem;
          flex: 1;
          margin-right: 0.75rem;
          .infoTop{
            display: flex;
            align-items: center;
            .userName{
              font-size: 0.7rem;
              font-weight: bold;
            }
            .userTel{
              font-size: 0.6rem;
              color: #999;
              margin: 0 0.5rem;
            }
            .addressDeft{
              padding: 0.15rem 0.5rem;
              background-color: #61CCD3;
              color: white;
              font-size: 0.6rem;
              border-radius: 0.15rem;
            }
          }
          .infoAddress{
            width: 100%;
            font-size: 0.6rem;
            line-height: 0.8rem;
            max-height: 1.6rem;
            margin-top: 0.25rem;
            color: #999;
          }
        }
        .editIcon{
          font-size: 0.9rem;
          color: #61CCD3;
        }
      }
    }
    .userCont{
      width: 92%;
      margin: 0.75rem 4%;
      padding: 0.75rem;
      box-sizing: border-box;
      background-color: #fff;
      border-radius: 0.25rem;
      display: flex;
      align-items: center;
      .userImg{
        width: 2.5rem;
        img{
          width: 100%;
          border-radius: 50%;
        }
      }
      .userInfo{
        flex: 1;
        margin-left: 0.75rem;
        .goodsName{
            width: 100%;
            font-size: 0.7rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .goodsNameLeft{
                display: flex;
                align-items: center;
                .newTag{
                    background-color: #6455d4;
                    color: white;
                    font-size: 0.6rem;
                    padding: 0.05rem 0.5rem;
                    border-radius: 0.1rem;
                    margin-right:0.5rem;
                }
            }
            .goodsSex{
                color: #6455d4;
            }
            
        }
        .orderTime{
            font-size: 0.6rem;
            color: #666;
            margin-top: 0.5rem;
            display: flex;
            align-items: center;
            
            .orderIconItem{
                display: flex;
                align-items: center;
                margin-right: 0.5rem;
            }
            .iconfont{
                color: #6455d4;
                margin-right: 0.25rem;
            }
            .orderNum{
                margin-left: 0.75em;
            }
        }
      }
    }
    .detailInfo{
      width: 92%;
      background-color: #fff;
      padding: 0.75rem;
      box-sizing: border-box;
      border-radius: 0.25rem;
      margin: 0.75rem auto 0;
      .shopTop{
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        .shopNameCont{
          flex: 1;
          width: 0.5rem;
          display: flex;
          padding: 0.75rem 0;
          align-items: center;
          margin-right: 0.5rem;
          .shopicon{
            font-size: 1.1rem;
            margin-right: 0.25rem;
          }
          .shopName{
            font-size: 0.7rem;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .icon-jinrujiantou{
            font-size: 0.8rem;
            position: relative;
          }
        }
        .orderStatus{
          color: #f9406e;
          font-size: 0.6rem;
        }
      }
      .goodsList{
        width: 100%;
        .goodsItem{
          width: 100%;
          margin-bottom: 1rem;
          display: flex;
          align-items: center;
          .goodsImg{
            width: 4rem;
            height: 4rem;
            overflow: hidden;
            border-radius: 0.25rem;
            margin-right: 0.5rem;
            img{
              width: 100%;
            }
          }
          .goodsInfo{
            width: 0.5rem;
            flex: 1;
            display: flex;
            flex-direction: column;
            height: 4rem;
            justify-content: space-between;
            .goodsName{
              width: 100%;
              line-height: 1rem;
              font-size: 0.7rem;
            }
            .orderTime{
                font-size: 0.6rem;
                color: #666;
            }
            .goodsType{
              display: flex;
              align-items: center;
              justify-content: space-between;
              .goodsNumCont{
                display: flex;
                height: 1rem;
                line-height: 1rem;
                color: #999;
                font-size: 0.6rem;
                align-items: center;
              }
              .goodsTypeItem{
                padding:0.1rem 0.5rem;
                background-color: #F6F6F6;
                font-size: 0.6rem;
                height: 1rem;
                line-height: 1rem;
                border-radius: 0.75rem;
                color: #999;
              }
            }
            .goodsInfoPrice{
              color: #999;
              display: flex;
              justify-content: space-between;
              font-size: 0.6rem;
            }
          }
        }
      }
      .formCont{
        width: 100%;
        background-color: #fff;
        .formItem{
          display: flex;
          justify-content: space-between;
          padding: 0.75rem 0;
          align-items: center;
          color: #666;
          font-size: 0.7rem;
          border-bottom: 1px dashed #ccc;
        }
        .noFlex{
          display: block;
          .setCarItem{
            display: flex;
            margin-bottom: 0.25rem;
            justify-content: space-between;
          }
        }
      }
    }
    
    .orderDesCont{
      width: 100%;
      padding: 0 4%;
      box-sizing: border-box;
      margin: 1rem 0;
    }
    .ctrlCont{
      width: 100%;
      padding: 0.5rem 4%;
      box-sizing: border-box;
      position: fixed;
      bottom: 0;
      left: 0;
      background-color: #fff;
      display: flex;
      justify-content: flex-end;
      text-align: center;
      .orderBtn{
        padding: 0.35rem 0;
        width: 25%;
        text-align: center;
        border-radius: 2rem;
        font-size: 0.7rem;
        box-sizing: border-box;
        margin-left: 0.5rem;
      }
      .pinkBtn{
        border: 1px solid #FF59B5;
        color: #FF59B5;
      }
      .greenBtn{
        border: 1px solid #32b444;
        color:#32b444;
      }
      .blackBtn{
        border: 1px solid #999;
        color: #666;
      }
    }
    .maskAddress{
      width: 100%;
      padding: 0.75rem 4%;
      box-sizing: border-box;
      .addressItem{
        background-color: #fff;
        padding: 0.5rem;
        box-sizing: border-box;
        border-radius: 0.25rem;
        display: flex;
        width: 100%;
        align-items: center;
        .addressImg{
          width: 2rem;
          height: 2rem;
          border-radius: 50%;
          text-align: center;
          line-height:2rem;
          font-size: 0.8rem;
          background-color: #61CCD3;
          color: white;
          margin-right: 0.75rem;
        }
        .addressInfo{
          width: 0.5rem;
          flex: 1;
          margin-right: 0.75rem;
          .infoTop{
            display: flex;
            align-items: center;
            .userName{
              font-size: 0.7rem;
              font-weight: bold;
            }
            .userTel{
              font-size: 0.6rem;
              color: #999;
              margin: 0 0.5rem;
            }
            .addressDeft{
              padding: 0.15rem 0.5rem;
              background-color: #61CCD3;
              color: white;
              font-size: 0.6rem;
              border-radius: 0.15rem;
            }
          }
          .infoAddress{
            width: 100%;
            font-size: 0.6rem;
            line-height: 0.8rem;
            max-height: 1.6rem;
            margin-top: 0.25rem;
            color: #999;
          }
        }
        .checkAddress{
          font-size: 0.7rem;
          color: white;
          // color: #61CCD3;
          width: 0.9rem;
          line-height: 0.9rem;
          height: 0.9rem;
          border: 1px solid #61CCD3;
          text-align: center;
          border-radius: 50%;
        }
        .checkAddressActive{
          background-color: #61CCD3;
        }
      }
    }
  }
  .haspadding{
    padding-bottom: 1rem;
  }
  </style>
  